import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import java.util.Scanner;

import app.TianQi.TianQiPa;
import app.TianQi.UrlManage;
import qiurank.Common;
import qiurank.Config;
import qiurank.DB;
import qiurank.Log;
import qiurank.ThreadManage;
import qiurank.UrlObject;

/**
 * Created by Administrator on 2015/12/31.
 */
public class Pachong {
    public static final void main(String[] args){
        /*
        DB.Table u=DB.table("url");
        try {
            u.truncate();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        ThreadManage threadManage=new ThreadManage();
        threadManage.createNewThread();
        //threadManage.createNewThread();
        //threadManage.createNewThread();
        while (true){
        }
        */

/*

        for(int i=0;i<10;i++){
            TouTiaoPa pa=new TouTiaoPa("http://toutiao.com/articles_news_car/",new UrlManage());
            new TouTiaoHandle().handle(pa);
            pa=new TouTiaoPa("http://toutiao.com/articles_digital/",new UrlManage());
            new TouTiaoHandle().handle(pa);
        }
*/
/*
        for(long i=0;i<10000;i++) {
            UrlModel m=new UrlModel();
            m.addUrl("http://toutiao.com/articles_news_car/", 10);
        }
*/
        //TouTiaoPa pa = PaFactory.createPa("http://toutiao.com/articles_news_car/", new UrlManage());
        //new TouTiaoHandle().handle(pa);
        //UrlModel model=new UrlModel();
        //Log.console(model.isExistDB("http://blog.csdn.net/xiangsuixinsheng/article/details/6871868"));
        //SameWordModel sameWordModel=new SameWordModel();
        //Log.console(sameWordModel.replaceContent("那个 asdfsdafsadfsadfsdafsa"));
       // ThreadManage threadManage=new ThreadManage();
       // threadManage.createNewThread();
        //threadManage.stopAllThread();
        /*
            File file=new File("E:\\pachong\\pachong2\\k.txt");
            if(file.isFile() && file.exists()){
                    try {
                            InputStreamReader read = new InputStreamReader(new FileInputStream(file),"utf8");
                            BufferedReader bufferedReader = new BufferedReader(read);
                            String line="";
                        DB.Table same=DB.table("sameword");
                            while ((line=bufferedReader.readLine())!=null){
                                if(!line.isEmpty()){
                                    String k[]=line.split(" ");
                                    Map<String ,Object>map=new HashMap<>();
                                    map.put("keyword",k[0]);
                                    map.put("keyword2",k[1]);
                                    same.insert(map);
                                }

                            }
                        Log.console("执行完毕");
                    } catch (Exception e) {
                            e.printStackTrace();
                    }
            }
*/

        ThreadManage threadManage=new ThreadManage();
        threadManage.createNewThread();
        threadManage.createNewThread();
        threadManage.createNewThread();
        while (true){
            if(threadManage.getFinish()){
                Log.console("执行完毕!,结束所有.");
                break;
            }
            try {
                //Log.console("执行主进程............");
                Thread.sleep(16000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }



    /*
        UrlObject urlObject=new UrlObject();
        urlObject.url="http://www.weather.com.cn/weather/101230201.shtml";
        //urlObject.url="http://www.weather.com.cn/weather/101230201.shtml";
        //urlObject.params="101230201";
        urlObject.params="101230201";
        TianQiPa pa=new TianQiPa(urlObject,new UrlManage());
        Map<String,Object> map=pa.tomorrowWeather();
        Log.console(map.toString());
        */
        //Log.console(map.toString());

        //Log.console(Config.config_path);
        /*
        DB.Table area=DB.table("area");
        DB.Table city=DB.table("city");
        try {
            city.select("DISTINCT weatherID,city").whereNotNull("weatherID").skip(0).take(1).orderBy("weatherID","desc");
            ResultSet rs=area.select("DISTINCT weatherID,area").whereNotNull("weatherID").union(city).get();
            rs.next();
            Log.console(rs.getString("weatherID"));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        */
        //Log.console(Config.getValue("db_name"));
    }
}
